package com.o2opays.wechat.service.Impl;

import com.o2opays.wechat.Enum.EnApi;
import com.o2opays.wechat.pojo.HttpResult;
import com.o2opays.wechat.pojo.TranListReuest;
import com.o2opays.wechat.pojo.TranRegisterRequest;
import com.o2opays.wechat.service.TranInfoService;
import com.o2opays.wechat.tool.HttpClientUtil;
import com.o2opays.wechat.tool.JsonUtil;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;


import java.util.Map;

/**
 * Created by tugou on 2017/12/4.
 */
@Service
public class TranInfoListServiceImpl implements TranInfoService {

    @Value("${service_url}")
    private String service_url;

    @Override
    public HttpResult getTranInfoList(TranListReuest reuest) {
        String url = service_url + EnApi.getTranInfoListByMrchId;
        StringBuffer parStr = new StringBuffer();
        if(reuest.getMrchId() != null && !"".equals(reuest.getMrchId())){
            parStr.append("&mrchId=");
            parStr.append(reuest.getMrchId());
        }
        if(reuest.getCount() != null && reuest.getCount() != 0){
            parStr.append("&count=");
            parStr.append(reuest.getCount());
        }
        if(reuest.getPageNo() != null && reuest.getPageNo() != 0){
            parStr.append("&pageNo=");
            parStr.append(reuest.getPageNo());
        }
        if(parStr.length() != 0) {
            parStr.deleteCharAt(0);
            url += "?"+parStr.toString();
        }
        String result = HttpClientUtil.doGet(url);
        HttpResult httpResult = JsonUtil.toObject(result,HttpResult.class);
        return httpResult;
    }

    @Override
    public HttpResult getRegisteronLineByMrchId(TranRegisterRequest request) {
        String url = service_url + EnApi.getRegisteronLineByMrchId;
        StringBuffer parStr = new StringBuffer();
        if(request.getMrchId() != null && !"".equals(request.getMrchId())){
            parStr.append("&mrchId=");
            parStr.append(request.getMrchId());
        }
        if(request.getCount() != null && request.getCount() != 0){
            parStr.append("&count=");
            parStr.append(request.getCount());
        }
        if(request.getPageNo() != null && request.getPageNo() != 0){
            parStr.append("&pageNo=");
            parStr.append(request.getPageNo());
        }
        if(parStr.length() != 0) {
            parStr.deleteCharAt(0);
            url += "?"+parStr.toString();
        }
        String result = HttpClientUtil.doGet(url);
        HttpResult httpResult = JsonUtil.toObject(result,HttpResult.class);
        return httpResult;
    }
}
